package com.ljx.api.controller;

import com.ljx.api.entity.Token;
import com.ljx.api.service.UserService;
import com.ljx.common.core.Result;
import com.ljx.common.utils.JwtUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.ljx.api.constrant.GlobalConstrant.TOKEN_PASSWORD;

/**
 * @类名: IndexController
 * @描述:
 * @日期: 2020-09-07 15:48
 * @作者: 刘纪譞
 * @版本: 1.0.0
 * <p>
 * since JDK 1.8
 **/
@Slf4j
@RestController
@RequestMapping("/index")
public class IndexController {
    @Autowired
    private UserService userService;
    @PostMapping("login")
    public Result login(String username, String password){
        if(userService.login(username, password)){
            Token token=new Token();
            log.info(username+password);
//                String ss = JwtUtils.sign(username, password);
          token.setToken(JwtUtils.sign(username,TOKEN_PASSWORD));
            return Result.success(token);
        }else {
            return Result.fail("登录失败");
        }
    }

    @GetMapping("/menu")
    public Result getMenu(){
        return Result.success();
    }
}
